//******************************************************************
//  PP5_7.java   Author: Tang Caiming
//
//  人机交互 石头-剪子-布 游戏.
//******************************************************************


import java.util.*;

public class PP5_7
{
   public static void main(String[] args)
   {
      //------------------------------------------------------------
      //  隐藏电脑输出，最后计算双方输赢及和局次数.
      //------------------------------------------------------------
       Scanner scan = new Scanner(System.in);
       Random generator = new Random();
       //  计数电脑赢次、用户赢次、平局次数；电脑输入，用户输入。
       int computer = 0, user = 0, draw = 0, ran = 0, num = 0;
       String another = "y";

       while (another.equalsIgnoreCase("y"))
       {
           System.out.println("1=石头， 2=布， 3=剪子;  你要出什么：");
           another = scan.nextLine();
           num = Integer.parseInt(another);

           while (num < 0 || num > 3)
           {
               System.out.println("输入无效，请重新输入：");
               num = scan.nextInt();
               break;
           }

           ran = generator.nextInt(3) + 1;
           System.out.println("你出的是：" + num);
           if (num == ran)
               draw++;
           else
               if ((num == 1 && ran == 2) || (num == 2 && ran == 3) || (num == 3 && ran == 1))
                  computer++;
           else
               if ((ran == 1 && num ==2) || (ran == 2 && num == 3) || (ran == 3 && num == 1 ))
                  user++;

           System.out.println();
           System.out.println("是否继续？（y/n）");
           another = scan.nextLine();

       }
       System.out.println("电脑胜利次数" + computer + "\n人胜利次数" + user  + "\n平局次数" + draw);
   }
}
